package de.tabuma.pm.gadget.controller;

import de.tabuma.pm.*;
import de.tabuma.pm.gadget.entity.*;
import de.tabuma.pm.gadget.logik.*;
import de.tabuma.lib.tabumacontroller;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import com.google.appengine.api.users.*;

/**
 *
 * @author alefen
 */
public class create extends tabumacontroller {

    public create(String servlet, Hashtable hashtable) {
        super(servlet, hashtable);
    }

    @Override
    public void navigate(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
        request.setAttribute(constants.gadgetActionId, "" + constants.GADGET_ACTION_CREATE);
        if(request.getParameter(constants.GADGET_ACTION_CREATE1)!=null) {
            String projectId = request.getParameter(constants.projectId);
            int projectIdInt = Integer.valueOf(projectId).intValue();
            Gadget gadget = new Gadget();
            String name = request.getParameter(constants.GADGET_NAME);
            gadget.setName(name);
            gadget.setNavMode(0);
            gadget.setNavModeElementId(0);
            gadget.setProjectId(projectIdInt);

            UserService userService = UserServiceFactory.getUserService();
            User user = userService.getCurrentUser();

            GadgetFacade.create(gadget, user.getEmail());
            
            list list = new list(this.getServlet(), this.getParameter());
            list.navigate(context, request, response, out);
        }
    }
}
